﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Xml;
using DataAccessLayer.Entites;
namespace DataAccessLayer.DAL
{
    public class PostDAL
    {
        public List<Post> GetXmlToList()
        {
            var list = new List<Post>();
            var xmld = new XmlDocument();
            xmld.Load(HttpContext.Current.Server.MapPath("~/XML/Post.xml"));
            var xmlnl = xmld.SelectNodes("/post/item");
            try
            {
                foreach (XmlNode xn in xmlnl)
                {
                    var t = new Post
                    {
                        Title = xn["title"].InnerText,
                        UserId = xn["writer"].InnerText,
                        Tag = xn["tag"].InnerText,
                        Intro = xn["intro"].InnerText,
                        Date = xn["date"].InnerText,
                        IntroImage = xn["image"].InnerText,
                        Content = xn["content"].InnerText,
                        ContentImage = xn["contentimage"].InnerText
                    };
                    list.Add(t);
                }
            }
            catch (NullReferenceException e)
            {
                throw;
            }
            return list;
        }
    }
}